﻿#pragma once
// Copyright (c) lanyeo 2020-2021
// Licenced under MIT license. See https://opensource.org/licenses/MIT for details.
// code style
// 1. use forward declaration (尽可能使用前置声明)
// 2. include file sequence [other project>c>c++>third>self project]
//

#include <string>
#include <vector>
#include <list>

#include <cppcoro/single_consumer_event.hpp>
#include <google/protobuf/message.h>

const std::string DB_OPTION_KEY = std::string("key");

enum DBErrorCode
{
    DB_CONNECT_FAIL = -2,
    DB_FAIL = -1,
    DB_OK = 0,
};

struct DBConnectKey
{
    std::string host;
    std::string username;
    std::string password;
    std::string database;
    unsigned port;

    DBConnectKey() : port(0)
    {

    }
};

typedef std::vector<DBConnectKey> DBConnectKeyVec;

struct DBConf
{
    DBConnectKeyVec connectKeys;
};

struct DBOperate
{
    bool is_co;
    cppcoro::single_consumer_event lock;
    std::string sql;
    std::list<google::protobuf::Message*>* results;
    google::protobuf::Message* what;
    int ret;
    DBOperate() : is_co(false), ret(0), what(nullptr)
    {

    }
};

struct DBCondition
{
    std::string key;
    std::string val;
    int op;
};

